#!/bin/sh
#
# /etc/rc.d/rc.seedd: start and stop BitBabbler TRNG(s).

BBOPTS="--daemon --config=/etc/bit-babbler/seedd.conf"
BBSOCKET=/run/bit-babbler/seedd.socket

seedd_start() {
  if [ -S $BBSOCKET ]; then
    echo 'seedd appears to be already running!'
    exit 1
  else
    echo 'Checking for BitBabbler...'
    /usr/bin/seedd --scan 
    echo "Starting seedd:  /usr/bin/seedd $BBOPTS"
    /usr/bin/seedd $BBOPTS 
  fi
}

seedd_stop() {
  echo 'Stopping seedd...'
  killall -w seedd
  # daemon doesn't clean up lock on termination.
  rm -f $BBSOCKET.lock
}

seedd_restart() {
  seedd_stop
  sleep 2  # ...take a breath...
  seedd_start
}

case "$1" in
    'start') seedd_start;;
  'restart') seedd_restart;;
     'stop') seedd_stop;;
          *) echo "usage $0 start|restart|stop";;
esac
